package com.playfab
{
    import com.playfab.<%- api.name %>Models.*;

    public class PlayFab<%- api.name %>API
    {
<% for(var i in api.calls) { var apiCall = api.calls[i]; %><%- getDeprecationAttribute("        ", apiCall)
%>        public static function <%- apiCall.name %>(request:<%- apiCall.request %>, onComplete:Function, onError:Function):void
        {
<%- getRequestActions("            ", apiCall) %>
            var requetJson:String = JSON.stringify( request );

            var onPostComplete:Function = function(resultData:Object, error:PlayFabError):void
            {
                if(error)
                {
                    if(onError != null)
                        onError(error);
                    if(PlayFabSettings.GlobalErrorHandler != null)
                        PlayFabSettings.GlobalErrorHandler(error);
                }
                else
                {
                    var result:<%- apiCall.result %> = new <%- apiCall.result %>(resultData);
<%- getResultActions("                    ", apiCall, api) %>
                    if(onComplete != null)
                        onComplete(result);
                }
            }

            PlayFabHTTP.post(PlayFabSettings.GetURL("<%- apiCall.url %>"), requetJson, <%- getAuthParams(apiCall) %>, onPostComplete);
        }

<% } %><% if (hasClientOptions) {
%>        public static function MultiStepClientLogin(needsAttribution:Boolean):void
        {
            if (needsAttribution && !PlayFabSettings.DisableAdvertising && (PlayFabSettings.AdvertisingIdType != null && PlayFabSettings.AdvertisingIdType != "") && (PlayFabSettings.AdvertisingIdValue != null && PlayFabSettings.AdvertisingIdValue != ""))
            {
                var request:AttributeInstallRequest = new AttributeInstallRequest();
                if (PlayFabSettings.AdvertisingIdType == PlayFabSettings.AD_TYPE_IDFA)
                    request.Idfa = PlayFabSettings.AdvertisingIdValue;
                else if (PlayFabSettings.AdvertisingIdType == PlayFabSettings.AD_TYPE_ANDROID_ID)
                    request.Adid = PlayFabSettings.AdvertisingIdValue;
                else
                    return;
                AttributeInstall(request, null, null);
            }
        }
<% } %>    }
}
